/*** Eclipse Class Decompiler plugin, copyright (c) 2016 Chen Chao (cnfree2000@hotmail.com) ***/
package nc.bs.dao;

import java.lang.reflect.Array;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import nc.bs.dao.DAOException;
import nc.bs.logging.Logger;
import nc.itf.uap.IUAPQueryBS;
import nc.itf.uap.IVOPersistence;
import nc.jdbc.framework.DataSourceCenter;
import nc.jdbc.framework.JdbcSession;
import nc.jdbc.framework.PersistenceManager;
import nc.jdbc.framework.SQLParameter;
import nc.jdbc.framework.exception.DbException;
import nc.jdbc.framework.mapping.IMappingMeta;
import nc.jdbc.framework.mapping.MappingMeta;
import nc.jdbc.framework.processor.BeanMappingListProcessor;
import nc.jdbc.framework.processor.ResultSetProcessor;
import nc.jdbc.framework.util.DBUtil;
import nc.vo.pub.SqlSupportVO;
import nc.vo.pub.SuperVO;
import nc.vo.pub.UpdateResultVO;

public final class BaseDAO implements IVOPersistence, IUAPQueryBS {
	private String dataSource = null;
	int maxRows = 100000;

	public BaseDAO() {
	}

	public BaseDAO(String dataSource) {
		this.dataSource = dataSource;
	}

	public Object executeQuery(String sql, ResultSetProcessor processor)
			throws DAOException {
		PersistenceManager manager = null;
		Object value = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			JdbcSession e = manager.getJdbcSession();
			value = e.executeQuery(sql, processor);
		} catch (DbException arg8) {
			Logger.error(arg8.getMessage(), arg8);
			throw new DAOException(arg8.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return value;
	}

	public Object executeQuery(String sql, SQLParameter parameter,
			ResultSetProcessor processor) throws DAOException {
		PersistenceManager manager = null;
		Object value = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			JdbcSession e = manager.getJdbcSession();
			value = e.executeQuery(sql, parameter, processor);
		} catch (DbException arg9) {
			Logger.error(arg9.getMessage(), arg9);
			throw new DAOException(arg9.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return value;
	}

	public int executeUpdate(String sql, SQLParameter parameter)
			throws DAOException {
		PersistenceManager manager = null;

		int value;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			JdbcSession e = manager.getJdbcSession();
			value = e.executeUpdate(sql, parameter);
		} catch (DbException arg8) {
			Logger.error(arg8.getMessage(), arg8);
			throw new DAOException(arg8.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return value;
	}

	public int executeUpdate(String sql) throws DAOException {
		PersistenceManager manager = null;

		int value;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			JdbcSession e = manager.getJdbcSession();
			value = e.executeUpdate(sql);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return value;
	}

	public Collection retrieveAll(Class className) throws DAOException {
		PersistenceManager manager = null;
		Collection values = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			values = manager.retrieveAll(className);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return values;
	}

	public Collection retrieveByClause(Class className, String condition)
			throws DAOException {
		PersistenceManager manager = null;
		Collection values = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			values = manager.retrieveByClause(className, condition);
		} catch (DbException arg8) {
			Logger.error(arg8.getMessage(), arg8);
			throw new DAOException(arg8.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return values;
	}

	public Collection retrieveByClause(Class className, String condition,
			SQLParameter params) throws DAOException {
		return this.retrieveByClause(className, condition, (String[]) null,
				params);
	}

	public Collection retrieveByClause(Class className, String condition,
			String orderBy) throws DAOException {
		return this.retrieveByClause(className,
				(String) this.appendOrderBy(condition, orderBy),
				(String[]) ((String[]) null), (SQLParameter) null);
	}

	public Collection retrieveByClause(Class className, String condition,
			String orderBy, SQLParameter params) throws DAOException {
		return this
				.retrieveByClause(className,
						this.appendOrderBy(condition, orderBy),
						(String[]) null, params);
	}

	public Collection retrieveByClause(Class className, String condition,
			String[] fields) throws DAOException {
		return this.retrieveByClause(className, (String) condition,
				(String[]) fields, (SQLParameter) null);
	}

	public Collection retrieveByClause(Class className, String condition,
			String[] fields, SQLParameter params) throws DAOException {
		PersistenceManager manager = null;
		Collection values = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			values = manager.retrieveByClause(className, condition, fields,
					params);
		} catch (DbException arg10) {
			Logger.error(arg10.getMessage(), arg10);
			throw new DAOException(arg10.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return values;
	}

	public Collection retrieveByClause(Class className, String condition,
			String orderBy, String[] fields) throws DAOException {
		return this.retrieveByClause(className,
				this.appendOrderBy(condition, orderBy), fields);
	}

	public Collection retrieveByClause(Class className, String condition,
			String orderBy, String[] fields, SQLParameter params)
			throws DAOException {
		return this.retrieveByClause(className,
				this.appendOrderBy(condition, orderBy), fields, params);
	}

	private String appendOrderBy(String condition, String orderBy) {
		StringBuffer clause = new StringBuffer();
		if (condition != null) {
			clause.append(condition);
		}

		if (orderBy != null && condition == null) {
			clause.append("ORDER BY ").append(orderBy);
		}

		if (orderBy != null && condition != null) {
			clause.append(" ORDER BY ").append(orderBy);
		}

		return clause.toString();
	}

	public Object[] retrieveByClause(Class c, SqlSupportVO[] sqlvos,
			String fromStr, String strWhere, String strOrderBy)
			throws DAOException {
		if (sqlvos != null && sqlvos.length != 0) {
			if (fromStr == null) {
				throw new NullPointerException("fromStr is null;");
			} else {
				String[][] fields = new String[2][sqlvos.length];
				MappingMeta meta = new MappingMeta("", "");

				for (int manager = 0; manager < sqlvos.length; ++manager) {
					fields[0][manager] = sqlvos[manager].getSqlSelectField();
					fields[1][manager] = sqlvos[manager].getVoAttributeName();
					meta.addMapping(sqlvos[manager].getVoAttributeName(),
							sqlvos[manager].getSqlSelectField());
				}

				PersistenceManager arg18 = null;

				Object[] arg12;
				try {
					arg18 = this.createPersistenceManager(this.dataSource);
					JdbcSession e = arg18.getJdbcSession();
					StringBuffer sql = new StringBuffer("SELECT ");

					for (int processor = 0; processor < fields[0].length; ++processor) {
						sql.append(fields[0][processor]);
						if (processor != fields[0].length - 1) {
							sql.append(",");
						}
					}

					sql.append(" FROM ").append(fromStr);
					if (strWhere != null && strWhere.trim().length() != 0) {
						sql.append(" WHERE ").append(strWhere);
					}

					if (strOrderBy != null && strOrderBy.trim().length() != 0) {
						sql.append(" ORDER BY ").append(strOrderBy);
					}

					BeanMappingListProcessor arg19 = new BeanMappingListProcessor(
							c, meta);
					List result = (List) e.executeQuery(sql.toString(), arg19);
					arg12 = result.toArray((Object[]) ((Object[]) Array
							.newInstance(c, 0)));
				} catch (DbException arg16) {
					Logger.error(arg16.getMessage(), arg16);
					throw new DAOException(arg16.getMessage());
				} finally {
					if (arg18 != null) {
						arg18.release();
					}

				}

				return arg12;
			}
		} else {
			throw new NullPointerException("Sqlvos is null;");
		}
	}

	public Collection retrieve(SuperVO vo, boolean isAnd) throws DAOException {
		PersistenceManager manager = null;
		Collection values = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			values = manager.retrieve(vo, isAnd);
		} catch (DbException arg8) {
			Logger.error(arg8.getMessage(), arg8);
			throw new DAOException(arg8.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return values;
	}

	public Collection retrieve(SuperVO vo, boolean isAnd, String[] fields)
			throws DAOException {
		PersistenceManager manager = null;
		Collection values = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			values = manager.retrieve(vo, isAnd, fields);
		} catch (DbException arg9) {
			Logger.error(arg9.getMessage(), arg9);
			throw new DAOException(arg9.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return values;
	}

	public Collection retrieveByCorp(Class className, String pkCorp,
			String[] selectedFields) throws DAOException {
		PersistenceManager manager = null;
		Collection values = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			values = manager.retrieveByCorp(className, pkCorp, selectedFields);
		} catch (DbException arg9) {
			Logger.error(arg9.getMessage(), arg9);
			throw new DAOException(arg9.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return values;
	}

	public Collection retrieveByCorp(Class className, String pkCorp)
			throws DAOException {
		PersistenceManager manager = null;
		Collection values = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			values = manager.retrieveByCorp(className, pkCorp);
		} catch (DbException arg8) {
			Logger.error(arg8.getMessage(), arg8);
			throw new DAOException(arg8.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return values;
	}

	public Object retrieveByPK(Class className, String pk) throws DAOException {
		PersistenceManager manager = null;
		Object values = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			values = manager.retrieveByPK(className, pk);
		} catch (DbException arg8) {
			Logger.error(arg8.getMessage(), arg8);
			throw new DAOException(arg8.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return values;
	}

	public Object retrieveByPK(Class className, String pk,
			String[] selectedFields) throws DAOException {
		PersistenceManager manager = null;
		Object values = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			values = manager.retrieveByPK(className, pk, selectedFields);
		} catch (DbException arg9) {
			Logger.error(arg9.getMessage(), arg9);
			throw new DAOException(arg9.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return values;
	}

	public String insertVOWithPK(SuperVO vo) throws DAOException {
		PersistenceManager manager = null;
		String pk = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			pk = manager.insertWithPK(vo);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return pk;
	}

	public String insertVO(SuperVO vo) throws DAOException {
		PersistenceManager manager = null;
		String pk = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			pk = manager.insert(vo);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return pk;
	}

	public String[] insertVOArrayWithPK(SuperVO[] vo) throws DAOException {
		PersistenceManager manager = null;
		String[] pk = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			pk = manager.insertWithPK(vo);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return pk;
	}

	public String[] insertVOArray(SuperVO[] vo) throws DAOException {
		PersistenceManager manager = null;
		String[] pk = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			pk = manager.insert(vo);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return pk;
	}

	public String[] insertVOList(List vos) throws DAOException {
		PersistenceManager manager = null;
		String[] pk = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			pk = manager.insert(vos);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return pk;
	}

	public String insertObjectWithPK(Object vo, IMappingMeta meta)
			throws DAOException {
		PersistenceManager manager = null;

		String e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.insertObjectWithPK(vo, meta);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public String insertObject(Object vo, IMappingMeta meta)
			throws DAOException {
		PersistenceManager manager = null;

		String e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.insertObject(vo, meta);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public String[] insertObjectWithPK(Object[] vo, IMappingMeta meta)
			throws DAOException {
		PersistenceManager manager = null;

		String[] e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.insertObjectWithPK(vo, meta);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public String[] insertObject(Object[] vo, IMappingMeta meta)
			throws DAOException {
		PersistenceManager manager = null;

		String[] e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.insertObject(vo, meta);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public int updateVO(SuperVO vo) throws DAOException {
		return this.updateVOArray(new SuperVO[] { vo });
	}

	public void updateVO(SuperVO vo, String[] fieldNames) throws DAOException {
		this.updateVOArray(new SuperVO[] { vo }, fieldNames);
	}

	public int updateVOArray(SuperVO[] vos) throws DAOException {
		return this.updateVOArray(vos, (String[]) null);
	}

	public int updateVOArray(SuperVO[] vos, String[] fieldNames)
			throws DAOException {
		return this.updateVOArray(vos, fieldNames, (String) null,
				(SQLParameter) null);
	}

	public void updateVOList(List vos) throws DAOException {
		PersistenceManager manager = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			manager.update(vos);
		} catch (DbException arg6) {
			Logger.error(arg6.getMessage(), arg6);
			throw new DAOException(arg6.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

	}

	public int updateObject(Object vo, IMappingMeta meta) throws DAOException {
		return this.updateObject((Object) vo, meta, (String) null);
	}

	public int updateObject(Object[] vos, IMappingMeta meta)
			throws DAOException {
		return this.updateObject((Object[]) vos, meta, (String) null);
	}

	public UpdateResultVO execUpdateByVoState(SuperVO[] vos,
			String[] selectedFields) throws DAOException {
		ArrayList listInsert = new ArrayList();
		ArrayList listUpdate = new ArrayList();
		ArrayList listDelete = new ArrayList();

		for (int rsVO = 0; rsVO < vos.length; ++rsVO) {
			int status = vos[rsVO].getStatus();
			if (status == 2) {
				listInsert.add(vos[rsVO]);
			} else if (status == 1) {
				listUpdate.add(vos[rsVO]);
			} else if (status == 3) {
				listDelete.add(vos[rsVO]);
			}
		}

		UpdateResultVO arg7 = new UpdateResultVO();
		if (listInsert.size() > 0) {
			arg7.setPks(this.insertVOArray((SuperVO[]) ((SuperVO[]) listInsert
					.toArray(new SuperVO[listInsert.size()]))));
		}

		if (listUpdate.size() > 0) {
			this.updateVOArray((SuperVO[]) ((SuperVO[]) listUpdate
					.toArray(new SuperVO[listUpdate.size()])), selectedFields);
		}

		if (listDelete.size() > 0) {
			this.deleteVOArray((SuperVO[]) ((SuperVO[]) listDelete
					.toArray(new SuperVO[listDelete.size()])));
		}

		return arg7;
	}

	public UpdateResultVO execUpdateByVoState(SuperVO[] vos)
			throws DAOException {
		return this.execUpdateByVoState(vos, (String[]) null);
	}

	public void deleteVO(SuperVO vo) throws DAOException {
		PersistenceManager manager = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			manager.delete(vo);
		} catch (DbException arg6) {
			Logger.error(arg6.getMessage(), arg6);
			throw new DAOException(arg6.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

	}

	public void deleteVOArray(SuperVO[] vos) throws DAOException {
		PersistenceManager manager = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			manager.delete(vos);
		} catch (DbException arg6) {
			Logger.error(arg6.getMessage(), arg6);
			throw new DAOException(arg6.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

	}

	public void deleteByPKs(Class className, String[] pks) throws DAOException {
		PersistenceManager manager = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			manager.deleteByPKs(className, pks);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

	}

	public void deleteByClause(Class className, String wherestr)
			throws DAOException {
		PersistenceManager manager = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			manager.deleteByClause(className, wherestr);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

	}

	public void deleteByClause(Class className, String wherestr,
			SQLParameter params) throws DAOException {
		PersistenceManager manager = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			manager.deleteByClause(className, wherestr, params);
		} catch (DbException arg8) {
			Logger.error(arg8.getMessage(), arg8);
			throw new DAOException(arg8.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

	}

	public void deleteByPK(Class className, String pk) throws DAOException {
		PersistenceManager manager = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			manager.deleteByPK(className, pk);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

	}

	public void deleteVOList(List vos) throws DAOException {
		PersistenceManager manager = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			manager.delete(vos);
		} catch (DbException arg6) {
			Logger.error(arg6.getMessage(), arg6);
			throw new DAOException(arg6.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

	}

	public void deleteObject(Object vo, IMappingMeta meta) throws DAOException {
		PersistenceManager manager = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			manager.deleteObject(vo, meta);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

	}

	public void deleteObject(Object[] vos, IMappingMeta meta)
			throws DAOException {
		PersistenceManager manager = null;

		try {
			manager = this.createPersistenceManager(this.dataSource);
			manager.deleteObject(vos, meta);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

	}

	public Collection retrieve(Object vo, IMappingMeta meta)
			throws DAOException {
		PersistenceManager manager = null;

		Collection e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.retrieve(vo, meta);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public Collection retrieveAll(Class className, IMappingMeta meta)
			throws DAOException {
		PersistenceManager manager = null;

		Collection e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.retrieveAll(className, meta);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public Collection retrieveByClause(Class className, IMappingMeta meta,
			String condition) throws DAOException {
		PersistenceManager manager = null;

		Collection e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.retrieveByClause(className, meta, condition);
		} catch (DbException arg8) {
			Logger.error(arg8.getMessage(), arg8);
			throw new DAOException(arg8.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public Collection retrieveByClause(Class className, IMappingMeta meta,
			String condition, SQLParameter params) throws DAOException {
		return this.retrieveByClause(className, meta, condition,
				(String[]) null, params);
	}

	public Collection retrieveByClause(Class className, IMappingMeta meta,
			String condition, String[] fields, SQLParameter params)
			throws DAOException {
		PersistenceManager manager = null;

		Collection e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.retrieveByClause(className, meta, condition, fields,
					params);
		} catch (DbException arg10) {
			Logger.error(arg10.getMessage(), arg10);
			throw new DAOException(arg10.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public Collection retrieveByClause(Class className, IMappingMeta meta,
			String condition, String[] fields) throws DAOException {
		PersistenceManager manager = null;

		Collection e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.retrieveByClause(className, meta, condition, fields);
		} catch (DbException arg9) {
			Logger.error(arg9.getMessage(), arg9);
			throw new DAOException(arg9.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public int deleteByClause(IMappingMeta meta, String wherestr)
			throws DAOException {
		return this.deleteByClause((IMappingMeta) meta, wherestr,
				(SQLParameter) null);
	}

	public int deleteByClause(IMappingMeta meta, String wherestr,
			SQLParameter params) throws DAOException {
		PersistenceManager manager = null;

		int e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.deleteByClause(meta, wherestr, params);
		} catch (DbException arg8) {
			Logger.error(arg8.getMessage(), arg8);
			throw new DAOException(arg8.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public int deleteByPK(IMappingMeta meta, String pk) throws DAOException {
		PersistenceManager manager = null;

		int e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.deleteByPK(meta, pk);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public Collection retrieveByCorp(Class c, IMappingMeta meta, String pkCorp,
			String[] selectedFields) throws DAOException {
		PersistenceManager manager = null;

		Collection e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.retrieveByCorp(c, meta, pkCorp, selectedFields);
		} catch (DbException arg9) {
			Logger.error(arg9.getMessage(), arg9);
			throw new DAOException(arg9.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public Collection retrieveByCorp(Class c, IMappingMeta meta, String pkCorp)
			throws DAOException {
		PersistenceManager manager = null;

		Collection e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.retrieveByCorp(c, meta, pkCorp);
		} catch (DbException arg8) {
			Logger.error(arg8.getMessage(), arg8);
			throw new DAOException(arg8.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public Object retrieveByPK(Class className, IMappingMeta meta, String pk,
			String[] selectedFields) throws DAOException {
		PersistenceManager manager = null;

		Object e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.retrieveByPK(className, meta, pk, selectedFields);
		} catch (DbException arg9) {
			Logger.error(arg9.getMessage(), arg9);
			throw new DAOException(arg9.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public Object retrieveByPK(Class className, IMappingMeta meta, String pk)
			throws DAOException {
		PersistenceManager manager = null;

		Object e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.retrieveByPK(className, meta, pk);
		} catch (DbException arg8) {
			Logger.error(arg8.getMessage(), arg8);
			throw new DAOException(arg8.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public int updateObject(Object vo, IMappingMeta meta, String whereClause)
			throws DAOException {
		PersistenceManager manager = null;

		int e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.updateObject(vo, meta, whereClause);
		} catch (DbException arg8) {
			Logger.error(arg8.getMessage(), arg8);
			throw new DAOException(arg8.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public int updateObject(Object[] vos, IMappingMeta meta, String whereClause)
			throws DAOException {
		return this.updateObject(vos, meta, whereClause, (SQLParameter) null);
	}

	public int updateObject(Object[] vos, IMappingMeta meta,
			String whereClause, SQLParameter param) throws DAOException {
		PersistenceManager manager = null;

		int e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.updateObject(vos, meta, whereClause, param);
		} catch (DbException arg9) {
			Logger.error(arg9.getMessage(), arg9);
			throw new DAOException(arg9.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	public int getDBType() {
		return DataSourceCenter.getInstance().getDatabaseType(this.dataSource);
	}

	protected String getTableName(int dbType, String tableName) {
		String strTn = tableName;
		switch (dbType) {
		case 0:
		case 1:
			strTn = tableName.toUpperCase();
			break;
		case 2:
			strTn = tableName;
		}

		return strTn;
	}

	public boolean isTableExisted(String tableName) throws DAOException {
		if (tableName == null) {
			throw new NullPointerException("TableName is null!");
		} else {
			PersistenceManager manager = null;
			ResultSet rs = null;

			boolean arg5;
			try {
				manager = this.createPersistenceManager(this.dataSource);
				int e = manager.getDBType();
				DatabaseMetaData dbmd = manager.getMetaData();
				rs = dbmd.getTables(manager.getCatalog(), manager.getSchema(),
						this.getTableName(e, tableName),
						new String[] { "TABLE" });
				if (!rs.next()) {
					arg5 = false;
					return arg5;
				}

				arg5 = true;
			} catch (Exception arg9) {
				Logger.error(arg9.getMessage(), arg9);
				throw new DAOException(arg9.getMessage());
			} finally {
				DBUtil.closeRs(rs);
				if (manager != null) {
					manager.release();
				}

			}

			return arg5;
		}
	}

	public int getMaxRows() {
		return this.maxRows;
	}

	public void setMaxRows(int maxRows) {
		this.maxRows = maxRows;
	}

	public int deleteByPKs(IMappingMeta meta, String[] pks) throws DAOException {
		PersistenceManager manager = null;

		int e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.deleteByPKs(meta, pks);
		} catch (DbException arg7) {
			Logger.error(arg7.getMessage(), arg7);
			throw new DAOException(arg7.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}

	private PersistenceManager createPersistenceManager(String ds)
			throws DbException {
		PersistenceManager manager = PersistenceManager.getInstance(ds);
		manager.setMaxRows(this.maxRows);
		return manager;
	}

	public int updateVOArray(SuperVO[] vos, String[] fieldNames,
			String whereClause, SQLParameter param) throws DAOException {
		PersistenceManager manager = null;

		int e;
		try {
			manager = this.createPersistenceManager(this.dataSource);
			e = manager.update(vos, fieldNames, whereClause, param);
		} catch (DbException arg9) {
			Logger.error(arg9.getMessage(), arg9);
			throw new DAOException(arg9.getMessage());
		} finally {
			if (manager != null) {
				manager.release();
			}

		}

		return e;
	}
}